/**
 * 
 */
function initAjax() {// 初始化ajax
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
var loginPassName=false,loginPassPwd=false;
function loginNameChange(){//登陆检查用户名输入情况
	var name=document.getElementById("loginName").value;
	if(name=="")
	{
	loginPassName=false;
	document.getElementById("loginError").innerHTML="用户名不能为空";
	document.getElementById("loginName").value="邮箱/用户名/手机号";
	}
	else if(name.length<4){
		loginPassName=false;
		document.getElementById("loginError").innerHTML="账户长度不够";
	}else {
		loginPassName=true;
		document.getElementById("loginError").innerHTML="";
		loginPwdChang();
	}
}
function loginNameNull(){//登陆用户名文本框样式
	var name=document.getElementById("loginName").value;
	if(name=="邮箱/用户名/手机号"){
		loginPassName=false;
		document.getElementById("loginName").value="";
	}
}
function loginPwdChang() {//登陆密码文本框样式，密码检查
	var pwd=document.getElementById("loginPassword").value;
	if(pwd==null||pwd=="")
	{
	loginPassPwd=false;
	document.getElementById("loginError").innerHTML="密码不能为空";
	document.getElementById("loginPassword").type="text";
	document.getElementById("loginPassword").value="密码";
	}
	else if(pwd.length<6){
		loginPassPwd=false;
		document.getElementById("loginError").innerHTML="密码长度不够";
	}else {
		loginPassPwd=true;
		document.getElementById("loginError").innerHTML="";
		loginNameChange();
	}
}
function loginPwdNull(){//登陆密码文本框样式
	var pwd=document.getElementById("loginPassword").value;
	if(pwd=="密码"){
		loginPassPwd=false;
		document.getElementById("loginPassword").value="";
		document.getElementById("loginPassword").type="password";
	}
}
//管理员登录
function admin_login() {
	if(loginPassName==true&&loginPassPwd==true){
		var data={loginId:document.getElementById("loginName").value,
				loginPwd:document.getElementById("loginPassword").value};
		jQuery.ajax({
			url: "../Admin_UserServlet?type=login", 
			data:{data:JSON.stringify(data)}, 
			type: "post", 
			dataType: "json",
			success:function(data){
				if(data.admin_login=="pass"){
					window.location.href="index.jsp";
				}else{
					alert("账户不存在或密码错误");
				}
			}
		});
	}
}
//验证登录
function admin_isLogin() {
	jQuery.ajax({
		url:"../Admin_UserServlet?type=isLogin",
		data:null,
		type:"post",
		dataType:"json",
		success:function(data){
			if(data.admin_login=="pass"){
				document.getElementById("admin_name").innerHTML="管理员:"+data.name;
			}else{
				alert("请先登录");
				window.location.href="login.jsp";
			}
		}
	});
}